package com.btl.service.ai.support.rag.embedding.strategy;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Configuration
public class RetrieverStrategyFactory {

    private static final Map<EmbeddingModelTypeEnum, RetrieverStrategy> strategyMap = new ConcurrentHashMap<>();

    @Resource
    private ApplicationContext applicationContext;


    @PostConstruct
    void init() {
        Collection<RetrieverStrategy> values = applicationContext.getBeansOfType(RetrieverStrategy.class)
                .values();
        for (RetrieverStrategy value : values) {
            strategyMap.put(value.modelType(), value);
        }
    }

    public static RetrieverStrategy retrieverStrategy(EmbeddingModelTypeEnum embeddingModelTypeEnum) {
        return strategyMap.getOrDefault(embeddingModelTypeEnum, strategyMap.get(EmbeddingModelTypeEnum.LOCAL_BGE_SMALL_ZH_V15_EMBEDDING_MODEL));
    }
}
